package com.example.springdemo6;

import com.aop.AspectConfig;
import com.aop.UserDao;
import com.aop.UserDaoByAno;
import com.aop.UserImpl;
import com.bean.AnoConfig;
import com.bean.Customer;
import com.bean.CustomerByAno;
import com.bean.CustomerContructor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringDemo6Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringDemo6Application.class, args);

        ApplicationContext context = new ClassPathXmlApplicationContext("appConfig.xml");
//        Customer customer = (Customer) context.getBean("cu");
//        System.out.println("这是通过xml装配Bean的方式实现Setter注入");
//        System.out.println("id = " +customer.getId() + " name = "+customer.getUname() +
//                " password=" +customer.getPassword() + " age=" + customer.getAge());
//
//        System.out.println("*******************************");
//        System.out.println("基于构造器注入");
//        CustomerContructor cu2 = (CustomerContructor) context.getBean("cu2");
//        System.out.println("这是通过xml装配Bean的方式实现Setter注入");
//        System.out.println("id = " +cu2.getId() + " name = "+cu2.getUname() +
//                " password=" +cu2.getPassword() + " age=" + cu2.getAge());
//
//        System.out.println("*******以下通过注解方式实现bean装载" +
//                "************");
//        ApplicationContext con1 = new AnnotationConfigApplicationContext(AnoConfig.class);
//        CustomerByAno cuByAno = con1.getBean(CustomerByAno.class);
//        System.out.println("id = " +cuByAno.getId() + " name = "+cuByAno.getUname() +
//                " password=" +cuByAno.getPassword() + " age=" + cuByAno.getAge());

        //以下是基于XML方式实现的AspectJ
//        UserDao userImp = (UserDao) context.getBean("userImpl1");
//        userImp.addUser();

        //以下是基于注解方式实现的AspectJ
        ApplicationContext con2 = new AnnotationConfigApplicationContext(AspectConfig.class);
        UserDaoByAno u = con2.getBean(UserDaoByAno.class);
        u.addUser();


    }

    @GetMapping("/springDemo")
    public String sayHello() {
        return "first spring project";
    }

}
